<?php


namespace App\Aspect;

use App\Annotation\EsUp;
use App\Service\EsService;
use App\Service\ProductService;
use Hyperf\DbConnection\Db;
use Hyperf\Di\Annotation\Aspect;
use Hyperf\Di\Aop\AbstractAspect;
use Hyperf\Di\Aop\ProceedingJoinPoint;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpMessage\Server\Response;

/**
 * @Aspect
 */
class EsAspect extends AbstractAspect
{
    /**
     * @Inject
     * @var RequestInterface
     */
    protected $request;

    const TYPE_VALUE = [1=>'SPU',2=>'SKU',3=>'VIDEO',4=>'SHOP',5=>'CENTER',6=>'STAR'];


//    public $classes = [
//        'App\Service\EsService::es_add()',
//        'App\Service\EsService::shop_product_add',
//    ];

    // 要切入的注解，具体切入的还是使用了这些注解的类，仅可切入类注解和类方法注解
    public $annotations = [
        EsUp::class
    ];

    public function process(ProceedingJoinPoint $proceedingJoinPoint)
    {
        $result = $proceedingJoinPoint->process();

        $annotation = $proceedingJoinPoint->getAnnotationMetadata();
        $func = ''; $type='';
        foreach ($annotation->method as $key => $value) {
            $func = $value->action;
            $type = $value->type;
        };
        $params['id'] = $this->request->input('id',0);
        $params['shop_id'] = $this->request->input('shop_id',0);
        $params['product_id'] = $this->request->input('product_id',0);
        co(function () use($params,$func,$type) {
            make(ProductService::class)->up($params,$func,$type);
        });
        return $result;
    }


}